/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejemploxml;

import javax.swing.table.DefaultTableModel;
import org.w3c.dom.NodeList;

/**
 *
 * @author lynx
 */
public class Listar extends javax.swing.JFrame {

    private final String []encabezado = new String[] {"Id", "Nombre", "Apellido"};
    
    public Listar() {
        initComponents();
        NodeList nodos = Ejemploxml.accesoXML.obtenNodos();
        Object[][] datos = new Object[nodos.getLength()][encabezado.length];
        for(int i=0; i<nodos.getLength(); i++){
            NodeList hijos = nodos.item(i).getChildNodes();
            datos[i][0] = nodos.item(i).getAttributes().item(0).getNodeValue();
            for(int j=0; j<hijos.getLength(); j++){
                datos[i][j+1] = hijos.item(j).getTextContent();
            }
        }
        jTable1.setModel(new DefaultTableModel(datos, encabezado) );
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Listado");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
